package com.frinder.official.akka.dispatcher;

import akka.dispatch.Futures;
import com.frinder.official.spring.MyBaseActor;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import scala.concurrent.ExecutionContext;
import scala.concurrent.Future;

/**
 * Created by frinder on 2017/9/28.
 */
@Component
@Scope("prototype")
public class BlockingFutureActor extends MyBaseActor {

    ExecutionContext ec = getContext().dispatcher();

    @Override
    public Receive createReceive() {
        return receiveBuilder()
                .match(Integer.class, i -> {
                    log().info("Calling blocking Future: {}", i);
                    Future<Integer> f = Futures.future(() -> {
                        Thread.sleep(500);
                        log().info("Blocking future finished: {}", i);
                        return i;
                    }, ec);
                })
                .build();
    }

}
